<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>reverse</title>
</head>
<body>
<script type="text/javascript">
    function reverseString1(str) {
        return str.split('').reverse().join('');
    }
    function reverseString2(str) {
        var result='';
        for(var i=str.length;i>=0;i--){
            result+=str.charAt(i);
        }
        return result;
    }
    function reverseString3(strIn,pos,strOut) {
       if(pos<0) return strOut;
       strOut+=strIn.charAt(pos--);
        return reverseString3(strIn,pos,strOut);
    }
    function reverseString4(str) {
       var arr=Array.prototype.slice.call(str)
        return arr.reverse().join('');
    }
    function stack() {
        this.data=[];
        this.top=0;

    }
    stack.prototype={
        push:function push(element) {
            this.data[this.top++]=element;
        },
        pop:function pop() {
            return this.data[--this.top];
        },
        length:function () {
            return this.top;
        }

    }
    function reverseString5(str){
        var s=new stack();
        var arr= str.split('');
        var len=arr.length;
        var result='';
        for(var i=0;i<len;i++){
            s.push(arr[i]);
        }
        for(var i=0;i<len;i++){
            result+=s.pop(arr[i]);
        }
        return result;
    }
    var str='abcdefgty';
    var pos=str.length;
    var result='';
    console.log(reverseString1(str));
    console.log(reverseString2(str));
    console.log(reverseString3(str,pos,result));
    console.log(reverseString4(str));
    console.log(reverseString5(str));


        function repeat(arr) {
            for(var i=0,len=arr.length;i<len;i++){
                if(arr[i]==arr[i+1]&&arr[i+1]!=arr[i+2]){
                    console.log(arr[i])
                }
            }
        }

    repeat([1,2,2,3,3,3,4,4,4,4,5,5,5,5,5])





</script>
</body>
</html>